<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .parent{
            width:300px;
            height:300px;
            background: red;
            position: relative;;
        }
        .child{
            width: 100px;
            height: 100px;
            background: blue;
            position: absolute;
            top:50%;
            left:50%;
            /* 让child的左上角顶点置于parent的中心点 */
            /* margin-top:-50px;
            margin-left:-50px;
            /* 让child向左向上位移一半的height,width
                使child的中心点与parent中心点重合
             */ 
             transform:translate(-50%,-50%)
             /* 使child 于X轴方向向上偏移child的50%height
                于Y轴方向向左偏移child的50%width*/
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="child"></div>

    </div>
</body>
</html>